
    var studentArr=[  //数组
        {"stuNo":"001","stuName":"A仓","stuAge":11,"stuClass":"129","xgzq":"X仓"},
        {"stuNo":"002","stuName":"B仓","stuAge":11,"stuClass":"16789","xgzq":"X仓"},
        {"stuNo":"003","stuName":"C仓","stuAge":48,"stuClass":"1289","xgzq":"X仓"},
        {"stuNo":"004","stuName":"D仓","stuAge":15,"stuClass":"1239","xgzq":"X仓"},
        {"stuNo":"005","stuName":"E仓","stuAge":45,"stuClass":"16789","xgzq":"X仓"},
        {"stuNo":"006","stuName":"F仓","stuAge":77,"stuClass":"56789","xgzq":"X仓"},
        {"stuNo":"007","stuName":"G仓","stuAge":33,"stuClass":"15789","xgzq":"X仓"},
        {"stuNo":"008","stuName":"H仓","stuAge":55,"stuClass":"1289","xgzq":"X仓"},
        {"stuNo":"009","stuName":"I仓","stuAge":44,"stuClass":"16789","xgzq":"X仓"}
    ];


   
        let arr = ['AA仓','BB仓','BB仓','CC仓','CC仓','CC仓']
        let com = document.getElementById("select_one");
    for( let i = 0;i<arr.length;i++){
	    com.options.add(new Option(arr[i],i));
    }
    let options = document.getElementById("select_one").options;
    for(let i = 0;i<options.length;i++){
	    if(options[i].value==2){//根据id选中阿里
		options[i].selected = true;
	    }
    }
    com.options.remove(1);


    var stuNoOper="";
    dataStudent();
    $("btnAdd").onclick=AddStudent;
    $("zhezhao").onclick=function () {
        model("divAddStudent","hidden");
    };
    $("btnCancel").onclick=function () {
        model("divAddStudent","hidden");
    };
    $("btnAddData").onclick=addStudentData;
    //添加
    function addStudentData() {
        var stuNo =$("stuNo").value;
        var stuName =$("stuName").value;
        var stuAge =$("stuAge").value;
        var stuClass =$("stuClass").value;
        var xgzq =$("xgzq").value;
        if(stuNo==""){
            alert("门店编码不能为空");
            return;
        }else if (stuName==""){
            alert("门店名称不能为空");
            return;
        }else if (stuAge==""){
            alert("负责人名称不能为空");
            return;
        }else if (stuClass==""){
            alert("负责人联系方式不能为空");
            return;
        }else if (xgzq==""){
            alert("相关战区不能为空");
            return;
        }
        if (stuNoOper==""){
            if (checkStudentNo(stuNo)){
                alert("当前战区编码已经存在");
                return;
            }
            var  obj= {"stuNo":stuNo,"stuName":stuName,"stuAge":stuAge,"stuClass":stuClass,"xgzq":xgzq};
            studentArr.push(obj);
            if (confirm("添加成功，是否继续添加")){
                $("stuNo").value="";
                $("stuName").value="";
                $("stuAge").value="";
                $("stuClass").value="";
                $("xgzq").value="";
                dataStudent();
            }  else {
                model("divAddStudent","hidden");
                dataStudent();
            }
        }
        else {
            for(var i=0;i<studentArr.length;i++){
                if (studentArr[i].stuNo==stuNoOper){
                    studentArr[i].stuName=stuName;
                    studentArr[i].stuAge=stuAge;
                    studentArr[i].stuClass=stuClass;
                    studentArr[i].xgzq=xgzq;
                    alert("修改成功");
                    model("divAddStudent","hidden");
                    dataStudent();
                    break;
                }
            }
        }


    }
    //模态框方法
    function model(id,type) {
        type=type || "show";
        $("zhezhao").className=type;
        $(id).className=type;
    }
    //修改
    function  update(stuno) {
        console.log(123)
        var stuObj=getStudentBystuNO(stuno);
        if(stuObj){
            stuNoOper=stuno;
            model("divAddStudent");
            $("stuNo").value=stuObj.stuNo;
            $("stuName").value=stuObj.stuName;
            $("stuAge").value=stuObj.stuAge;
            $("stuClass").value=stuObj.stuClass;
            $("xgzq").value=stuObj.xgzq;
        }else {
            alert("输入有误")
        }
    }
    //获取修改信息
    function getStudentBystuNO(stuno) {
        for(var i=0;i<studentArr.length;i++){
            if(studentArr[i].stuNo==stuno){
                return studentArr[i];
            }
        }
        return null;
    }
    //添加，接收用户数据
    function AddStudent() {
        stuNoOper="";
        model("divAddStudent");
    }
    //数据显示
    function dataStudent() {
        var tbstudent=$("tbStudent");
        tbstudent.innerHTML="";
        for(var i=0; i<studentArr.length;i++){
                tbstudent.innerHTML+=`<tr><td>${studentArr[i].stuNo}</td><td>${studentArr[i].stuName}</td><td>${studentArr[i].stuAge}</td><td>${studentArr[i].stuClass}</td><td>${studentArr[i].xgzq}</td> 
                <td><button onclick = 'del(${studentArr[i].stuNo})'>删除</button><button onclick = 'update(${studentArr[i].stuNo})'>修改</button></td></tr>`
        }
    }
    //删除
    function del(stuno) {
        if (confirm("确定要删除吗")){
            for (var i=0;i<studentArr.length;i++){
                if(studentArr[i].stuNo==stuno){
                    studentArr.splice(i,1);
                    alert("删除成功");
                    dataStudent();
                    break;
                }
            }
        }
    }
    //删除全部
    function delAll() {
        if (confirm("确定要删除吗")){
            studentArr=[];
            dataStudent();
        }
    }
    //验证编码
    function checkStudentNo(stuNo) {
        for( var i=0;i<studentArr.length;i++){
            if(studentArr[i].stuNo==stuNo){
                return true;
            }
        }
        return false;
    }
    //选择id
    function $(id) {
        return document.getElementById(id);
    }


   